package com.sfx.concurrent.demo.concurrent.ExcutorService;

import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: sfx
 * Date: 2023-01-26
 * Time: 16:05
 */
@Slf4j(topic = "c.ClosingThreadPool")
public class TestShutdown {
    public static void main(String[] args) {
        ExecutorService service = Executors.newFixedThreadPool(2);
        Future<String> future1 = service.submit(new Callable<String>() {
            @Override
            public String call() throws Exception {
                log.debug("begin1...");
                Thread.sleep(1000);
                log.debug("end1...");
                return "1";
            }
        });

        Future<String> future2 = service.submit(() -> {
            log.debug("begin2...");
            Thread.sleep(1000);
            log.debug("end2...");
            return "2";
        });

        Future<String> future3 = service.submit(() -> {
            log.debug("begin3...");
            Thread.sleep(1000);
            log.debug("end3...");
            return "3";
        });

        log.debug("shutdown");
        List<Runnable> runnables = service.shutdownNow();
        log.debug("{}",runnables);
        log.debug("other");
        service.submit(() -> {
            log.debug("begin4...");
            Thread.sleep(1000);
            log.debug("end4...");
            return "4";
        });
    }
}
